package com.open.capacity.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.open.capacity.dao.CommentDao;
import com.open.capacity.model.CommentModel;
import com.open.capacity.model.UserModel;
import com.open.capacity.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: y_022
 * @date: 18:22-2021/6/24
 * @description:
 */
@Service
public class CommentServiceImpl  implements CommentService {
    @Autowired
    private CommentDao commentDao;

    /**
     * 分页查询评论
     * @param userModel
     * @return
     */
    @Override
    public PageInfo<CommentModel> findCommentByUserId(UserModel userModel) {
        PageHelper.startPage(userModel.getPagees()-1, userModel.getLimits());
        List<CommentModel> commentModelList = commentDao.findCommentByUserId(userModel);
        PageInfo<CommentModel> topicPageInfo = new PageInfo<>(commentModelList);
        return  topicPageInfo;
    }

    /**
     * 新增评论
     * @param commentModel
     */
    @Override
    public void addComment(CommentModel commentModel) {
        commentDao.addComment(commentModel);
    }

    @Override
    public void deleteComment(CommentModel commentModel) {
        commentDao.deleteComment(commentModel);
    }

    @Override
    public int findComment(CommentModel commentModel) {

        return  commentDao.findComment(commentModel);
    }
}
